package com.hdoit.apollo.logical.shop.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hdoit.apollo.logical.shop.dao.ICustomerDao;
import com.hdoit.apollo.logical.shop.model.Address;
import com.hdoit.apollo.logical.shop.model.Customer;
import com.hdoit.apollo.logical.shop.service.ICustomerService;
import com.hdoit.apollo.logical.viewmodel.shop.CustomerSearch;
import com.tennetcn.core.common.enums.pub.YesOrNoInteger;
import com.tennetcn.core.common.utils.CommonUtils;
import com.tennetcn.core.common.utils.DateUtils;
import com.tennetcn.data.dao.base.impl.SuperService;
import com.tennetcn.data.enums.ModelStatus;
/**
 * @author      tancongzhu
 * @email       
 * @createtime  2018年04月02日 17:48:26
 * @comment
 */
@Component
public class CustomerServiceImpl extends SuperService<Customer> implements ICustomerService{

	@Autowired
	private ICustomerDao customerDao;
	
	@Override
	public List<Customer> getCustomerListByCargoId(String cargoId) {
		
		return customerDao.getCustomerListByCargoId(cargoId);
	}

	@Override
	public Customer getCustomerByCustomerId(String customerId) {
		
		return customerDao.getCustomerByCustomerId(customerId);
	}

	@Override
	public boolean applyChange(Customer customer, List<Address> addresses) {
		boolean result=false;
		result=super.applyChange(customer);
		
			
		return result;
	}
	
	
	
	public boolean saveAddresses(Customer customer, List<Address> addresses){
		for (Address address : addresses) {
			address.setCustomerId(customer.getCustomerId());
			address.setAddressId(CommonUtils.getKeyId());
			address.setCreateDate(DateUtils.getCurrent());
			address.setDeleteMark(YesOrNoInteger.no);
			address.setModelStatus(ModelStatus.add);
		}
		
		return true;
	}

	@Override
	public Customer queryCustomerInfoByCustomerId(String customerId) {
		
		return customerDao.queryCustomerInfoByCustomerId(customerId);
	}

	@Override
	public Customer getCustomerById(String customerId, String shopId) {
		return customerDao.getCustomerById(customerId,shopId);
	}
	
	@Override
	public boolean saveCustomers(List<Customer> customers) {
		boolean result=false;
		result= (super.insertListEx(customers)==customers.size());
		
		return result;
	}

	@Override
	public Customer getRetailCustomer(String shopId) {
		return customerDao.getRetailCustomer(shopId);
	}

	@Override
	public List<Customer> getList(CustomerSearch search) {
		return customerDao.getList(search);
	}

	@Override
	public Customer queryModelByOpenId(String openId, String shopId) {
		
		return customerDao.queryModelByOpenId(openId,shopId);
	}



	

}
